package adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.tdam_2012_g7.R;

import entidades.Contacto;

public class ItemContactoAdapter extends ArrayAdapter<Contacto>{

	private ArrayList<Contacto> items;

	public ItemContactoAdapter(Context context, int textViewResourceId,ArrayList<Contacto> items) {
		super(context, textViewResourceId, items);
		this.items = items;
	}
	

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) this.getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			v = vi.inflate(R.layout.item_contacto, null);
		}
		Contacto cont = items.get(position);
		if (cont != null) {
			TextView ttitulo = (TextView) v
					.findViewById(R.id.txtNombreContacto);
			ttitulo.setText(cont.getNombre());
		}
		return v;
	}
	
	public void addContact(Contacto contact) {
		if (contact != null) {
			items.add(contact);
		}
	}
	
	public Contacto getContacto(int position) {
		Contacto contacto = (Contacto) getItem(position);
		return contacto;
	}
}
